<?php
/**
 * Created by PhpStorm.
 * User: peter
 * Date: 2018/7/16
 * Time: 下午12:31
 */

namespace app\admin\controller;


use think\Request;

class Express extends Base
{
    /**
     * @param Request $request
     * @return array
     * @throws \think\exception\PDOException
     */
    public function subscribeCallback (Request $request)
    {
        $data  = $request->post('param');
        return \app\admin\logic\Express::subscribeCallback(json_decode($data, true));
    }
    /**
     * @purpose 获取快递公司列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function items (Request $request)
    {
        $page       = $request->get('page', 1);
        $size       = $request->get('size', 40);
        $kw         = $request->get('kw', '');
        $where      = [];
        if ($kw) {
            $where[] = ['name', ['like', '%'.$kw],['like', '%'.$kw.'%'],['like', $kw.'%'], 'or'];
        }
        return \app\admin\logic\Express::items($where, $page, $size);
    }

    /**
     * @purpose 设置默认发货快递公司
     * @param Request $request
     * @return array
     */
    public function setDefault (Request $request)
    {
        $id             = $request->post('id');
        return \app\admin\logic\Express::setDefault($id);
    }

    /**
     * @purpose 获取默认发货快递
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getDefault ()
    {
        return \app\admin\logic\Express::getDefault();
    }

    /**
     * @purpose 搜索快递公司
     * @param Request $request
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function search (Request $request)
    {
        $kw =   $request->get('kw', '');
        return \app\admin\logic\Express::search($kw);
    }
}